// 引入发送请求的函数对象
import { defHttp } from '/@/utils/http/axios';
// 引入响应返回值的数据类型
import { CategoryListModel } from './model/categoryModel';

// 定义请求地址的枚举
enum Api {
  GetCategory1List = '/admin/product/getCategory1',
  GetCategory2List = '/admin/product/getCategory2',
  GetCategory3List = '/admin/product/getCategory3',
}

/**
 * 获取一级分类
 * @returns CategoryListModel
 */
export const getCategory1ListApi = () => {
  return defHttp.get<CategoryListModel>({
    url: Api.GetCategory1List,
  });
};

/**
 * 获取二级分类
 * @param category1Id 一级分类id
 * @returns CategoryListModel
 */
export const getCategory2ListApi = (category1Id: number) => {
  return defHttp.get<CategoryListModel>({
    url: Api.GetCategory2List,
    params: `/${category1Id}`,
  });
};

/**
 * 获取三级分类
 * @param category2Id 二级分类id
 * @returns CategoryListModel
 */
export const getCategory3ListApi = (category2Id: number) => {
  return defHttp.get<CategoryListModel>({
    url: Api.GetCategory3List,
    params: `/${category2Id}`,
  });
};
